package com.analysis.model;

import lombok.Data;
import java.util.*;

@Data
public class ClassDifference {
    private String className;
    private DifferenceType type;
    private List<String> addedFields = new ArrayList<>();
    private List<String> removedFields = new ArrayList<>();
    private Map<String, String> modifiedFields = new HashMap<>();
    private List<MethodDifference> methodDifferences = new ArrayList<>();
    private List<String> affectedApis = new ArrayList<>();
    // 新增：记录依赖此类的其他类
    private Set<String> dependentClasses = new HashSet<>();
    // 新增：记录依赖此类的方法（完整方法签名）
    private Set<String> dependentMethods = new HashSet<>();
    // 新增：记录依赖此类的API方法
    private Set<String> dependentApiMethods = new HashSet<>();

    public enum DifferenceType {
        ADDED("新增"),
        MODIFIED("修改"),
        DELETED("删除");

        private final String description;

        DifferenceType(String description) {
            this.description = description;
        }

        public String getDescription() {
            return description;
        }
    }

    public void addModifiedField(String fieldName, String modification) {
        modifiedFields.put(fieldName, modification);
    }

    public void addAddedField(String fieldName) {
        addedFields.add(fieldName);
    }

    public void addRemovedField(String fieldName) {
        removedFields.add(fieldName);
    }

    public void addDependentClass(String className) {
        dependentClasses.add(className);
    }

    public void addDependentMethod(String methodName) {
        dependentMethods.add(methodName);
    }

    public void addDependentApiMethod(String apiMethod) {
        dependentApiMethods.add(apiMethod);
    }

    public void addAffectedApi(String apiMethod) {
        if (affectedApis == null) {
            affectedApis = new ArrayList<>();
        }
        if (!affectedApis.contains(apiMethod)) {
            affectedApis.add(apiMethod);
        }
    }

    public List<String> getAddedFields() {
        return addedFields;
    }

    public List<String> getRemovedFields() {
        return removedFields;
    }

    public Map<String, String> getModifiedFields() {
        return modifiedFields;
    }

    public boolean hasChanges() {
        return !addedFields.isEmpty() || 
               !removedFields.isEmpty() || 
               !modifiedFields.isEmpty() || 
               (methodDifferences != null && !methodDifferences.isEmpty());
    }
}
